<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/dute_favicon_32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/dute_favicon_16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <link rel="manifest" href="/images/manifest.json">
  <meta name="msapplication-config" content="/images/browserconfig.xml">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="google-site-verification" content="mpI5dkydstZXl6UcDCppqktXK0bbvqdZ6LkZ3KNk4Iw">
  <meta name="baidu-site-verification" content="code-a1LksZX2Ds">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"whitestore.top","root":"/","scheme":"Gemini","version":"7.8.0","exturl":true,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="Neo4j使用">
<meta property="og:type" content="article">
<meta property="og:title" content="Neo4j + VIS 数据可视化问题汇总">
<meta property="og:url" content="https://whitestore.top/2020/07/26/note1/index.html">
<meta property="og:site_name" content="爱看书的阿东">
<meta property="og:description" content="Neo4j使用">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://raw.githubusercontent.com/lazyTimes/imageRepository/master/img/%E6%A0%87%E7%AD%BE%E5%BA%93%E9%9C%80%E6%B1%82.png?ynotemdtimestamp=1595748679079">
<meta property="og:image" content="https://raw.githubusercontent.com/lazyTimes/imageRepository/master/img/%E6%A0%87%E7%AD%BE%E5%BA%93%E9%9C%80%E6%B1%82.png?ynotemdtimestamp=1595748679079">
<meta property="article:published_time" content="2020-07-26T09:32:28.000Z">
<meta property="article:modified_time" content="2023-07-16T06:28:09.227Z">
<meta property="article:author" content="阿东">
<meta property="article:tag" content="Neo4j">
<meta property="article:tag" content="visjs">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://raw.githubusercontent.com/lazyTimes/imageRepository/master/img/%E6%A0%87%E7%AD%BE%E5%BA%93%E9%9C%80%E6%B1%82.png?ynotemdtimestamp=1595748679079">

<link rel="canonical" href="https://whitestore.top/2020/07/26/note1/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Neo4j + VIS 数据可视化问题汇总 | 爱看书的阿东</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="爱看书的阿东" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">爱看书的阿东</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">赐他一块白色石头，石头上写着新名</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://whitestore.top/2020/07/26/note1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="阿东">
      <meta itemprop="description" content="随遇而安">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="爱看书的阿东">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Neo4j + VIS 数据可视化问题汇总
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-07-26 17:32:28" itemprop="dateCreated datePublished" datetime="2020-07-26T17:32:28+08:00">2020-07-26</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2023-07-16 14:28:09" itemprop="dateModified" datetime="2023-07-16T14:28:09+08:00">2023-07-16</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/" itemprop="url" rel="index"><span itemprop="name">数据库</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/07/26/note1/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/07/26/note1/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>4.9k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>4 分钟</span>
            </span>
            <div class="post-description">Neo4j使用</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>被前端整的有点发虚，这里记录一下自己干的一些（蠢）事</p>
<blockquote>
<p>PS：这种无力感真的希望不要再有，在自己不怎么擅长的领域班门弄斧就是浪费时间</p>
</blockquote>
<a id="more"></a>

<h2 id="重要资料："><a href="#重要资料：" class="headerlink" title="重要资料："></a>重要资料：</h2><h2 id="VIS-DataSet-使用："><a href="#VIS-DataSet-使用：" class="headerlink" title="VIS DataSet 使用："></a>VIS DataSet 使用：</h2><p><span class="exturl" data-url="aHR0cHM6Ly92aXNqcy5naXRodWIuaW8vdmlzLWRhdGEvZGF0YS9kYXRhc2V0Lmh0bWw=" title="https://visjs.github.io/vis-data/data/dataset.html">dataSet使用<i class="fa fa-external-link"></i></span></p>
<p>这段时间做表标签库，内容还是比较多的，这里记录一下个人遇到的一些需求汇总问题</p>
<p><span class="exturl" data-url="aHR0cHM6Ly96aHVhbmxhbi56aGlodS5jb20vcC8zNjQwNDg3Mg==" title="https://zhuanlan.zhihu.com/p/36404872">什么是neo4j<i class="fa fa-external-link"></i></span></p>
<h1 id="Q：页面初始化如何控制节点的距离大小"><a href="#Q：页面初始化如何控制节点的距离大小" class="headerlink" title="Q：页面初始化如何控制节点的距离大小"></a>Q：页面初始化如何控制节点的距离大小</h1><p>A： 官方文档： <span class="exturl" data-url="aHR0cHM6Ly92aXNqcy5naXRodWIuaW8vdmlzLW5ldHdvcmsvZG9jcy9uZXR3b3JrL3BoeXNpY3MuaHRtbA==" title="https://visjs.github.io/vis-network/docs/network/physics.html">VIS的节点物理效果<i class="fa fa-external-link"></i></span></p>
<p>需要调整如下参数</p>
<p>在<code>options</code>调整如下变量</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"> &#x2F;&#x2F;力导向图效果</span><br><span class="line">physics: &#123;</span><br><span class="line">    enabled: true,   &#x2F;&#x2F; 是否开启vis引擎配置</span><br><span class="line">        barnesHut: &#123; &#x2F;&#x2F; 基于四叉树的重力模型，非分布式性能最好的求值器</span><br><span class="line">            gravitationalConstant: -4000, &#x2F;&#x2F;此参数确定了合并的远程力和各个短程力之间的边界。要过分简化，较高的值会更快，但是会产生更多的错误，较低的值会很慢，但是会减少错误。</span><br><span class="line">            centralGravity: 0.3, &#x2F;&#x2F;有一个中央引力吸引器，可将整个网络拉回到中心。</span><br><span class="line">            springLength: 120, &#x2F;&#x2F; 边缘被建模为弹簧。这里的springLength是弹簧的其余长度。</span><br><span class="line">            springConstant: 0.04, &#x2F;&#x2F;这就是弹簧的强度。值越高，表示弹簧越强。</span><br><span class="line">            damping: 0.09, &#x2F;&#x2F; 接受范围：[0 .. 1]。阻尼因子是前一次物理模拟迭代中有多少速度会延续到下一次迭代中。</span><br><span class="line">            avoidOverlap: 0 &#x2F;&#x2F; 接受范围：[0 .. 1]。大于0时，将考虑节点的大小。对于两个重力模型，将从节点的包围圆的半径计算距离。值1是最大避免重叠。</span><br><span class="line">		&#125;</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>

<p>根据上面的值基本可以确定整个页面的物理引擎效果</p>
<h1 id="Q：要实现鼠标悬停到页面变为小手的样式"><a href="#Q：要实现鼠标悬停到页面变为小手的样式" class="headerlink" title="Q：要实现鼠标悬停到页面变为小手的样式"></a>Q：要实现鼠标悬停到页面变为小手的样式</h1><p>A：</p>
<p>官方案例：<span class="exturl" data-url="aHR0cHM6Ly92aXNqcy5naXRodWIuaW8vdmlzLW5ldHdvcmsvZXhhbXBsZXMvbmV0d29yay9vdGhlci9jdXJzb3JDaGFuZ2UuaHRtbA==" title="https://visjs.github.io/vis-network/examples/network/other/cursorChange.html">https://visjs.github.io/vis-network/examples/network/other/cursorChange.html<i class="fa fa-external-link"></i></span></p>
<p>参考博客：<span class="exturl" data-url="aHR0cHM6Ly93d3cudGhpbmJ1Zy5jb20vcS80MDUzMjU5Ng==" title="https://www.thinbug.com/q/40532596">博客地址<i class="fa fa-external-link"></i></span></p>
<p>步骤：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">var networkCanvas &#x3D; document.getElementById(&quot;network_id&quot;).getElementsByTagName(&quot;canvas&quot;)[0];</span><br></pre></td></tr></table></figure>

<p>增加一个配置</p>
<p>最终解决方案：</p>
<p>在vis初始化<code>network</code> 之后,加入如下事件绑定代码</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">var cursor &#x3D;  network.canvas.body.container.style.cursor; &#x2F;&#x2F; 获取netword的cursor</span><br><span class="line">network.on(&quot;hoverNode&quot;, function (params) &#123;</span><br><span class="line">    cursor &#x3D; &#39;grab&#39;</span><br><span class="line">&#125;);</span><br><span class="line">network.on(&quot;blurNode&quot;, function() &#123;</span><br><span class="line">    cursor &#x3D; &#39;default&#39;</span><br><span class="line">&#125;);</span><br><span class="line">network.on(&quot;hoverEdge&quot;, function() &#123;</span><br><span class="line">    cursor &#x3D; &#39;grab&#39;</span><br><span class="line">&#125;);</span><br><span class="line">network.on(&quot;blurEdge&quot;, function() &#123;</span><br><span class="line">    cursor &#x3D; &#39;default&#39;</span><br><span class="line">&#125;);</span><br><span class="line">network.on(&quot;dragStart&quot;, function() &#123;</span><br><span class="line">    cursor &#x3D; &#39;grabbing&#39;</span><br><span class="line">&#125;);</span><br><span class="line">network.on(&quot;dragging&quot;, function() &#123;</span><br><span class="line">    cursor &#x3D; &#39;grabbing&#39;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<h1 id="Q：如何模仿Neo4j-用vis实现节点的展开和多层折叠"><a href="#Q：如何模仿Neo4j-用vis实现节点的展开和多层折叠" class="headerlink" title="Q：如何模仿Neo4j 用vis实现节点的展开和多层折叠"></a>Q：如何模仿Neo4j 用vis实现节点的展开和多层折叠</h1><p>参考：<span class="exturl" data-url="aHR0cHM6Ly93d3cuamlhbnNodS5jb20vcC9iMjI3MjdjOGZlNjA=" title="https://www.jianshu.com/p/b22727c8fe60">简书地址<i class="fa fa-external-link"></i></span></p>
<p>个人需求：</p>
<p>实现节点可以扩展和缩放，双击扩展，扩展之后再次双击为收缩</p>
<p>难点：如何实现多层节点收缩</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">var nodes &#x3D; [</span><br><span class="line">  &#123;id: 1, subids: [2, 3],allsubids:[2,3,4,5]&#125;,</span><br><span class="line">  &#123;id: 2, pid: 1&#125;,</span><br><span class="line">  &#123;id: 3, subids: [4],pid: 1,allsubids:[4,5]&#125;</span><br><span class="line">  &#123;id: 4, subids: [5],pid: 3&#125;</span><br><span class="line">  &#123;id: 5, pid: 4&#125;</span><br><span class="line">];</span><br><span class="line">var edges &#x3D; [</span><br><span class="line">  &#123;from:1,to:2&#125;,</span><br><span class="line">  &#123;from:1,to:3&#125;,</span><br><span class="line">  &#123;from:3,to:4&#125;,</span><br><span class="line">  &#123;from:4,to:5&#125;</span><br><span class="line">]</span><br></pre></td></tr></table></figure>

<h2 id="个人实现："><a href="#个人实现：" class="headerlink" title="个人实现："></a>个人实现：</h2><p>目前经过查找资料发现以下代码加上</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;*</span><br><span class="line">     *获取所有子节点</span><br><span class="line">     * network ：图形对象</span><br><span class="line">     * _thisNode ：单击的节点（父节点）</span><br><span class="line">     * _Allnodes ：用来装子节点ID的数组</span><br><span class="line">     * *&#x2F;</span><br><span class="line">    function getAllChilds(network,_thisNode,_Allnodes)&#123;</span><br><span class="line">        var _nodes &#x3D; network.getConnectedNodes(_thisNode);</span><br><span class="line">        if(_nodes.length &gt; 0)&#123;</span><br><span class="line">            for(var i&#x3D;0;i&lt;_nodes.length;i++)&#123;</span><br><span class="line">                &#x2F;&#x2F; getAllChilds(network,_nodes[i],_Allnodes);</span><br><span class="line">                _Allnodes.push(_nodes[i]);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        return _Allnodes</span><br><span class="line">    &#125;;</span><br></pre></td></tr></table></figure>

<p>增加两个<code>Array</code>的方法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">Array.prototype.indexOf &#x3D; function(val) &#123;</span><br><span class="line">       for (var i &#x3D; 0; i &lt; this.length; i++) &#123;</span><br><span class="line">           if (this[i] &#x3D;&#x3D; val) return i;</span><br><span class="line">       &#125;</span><br><span class="line">       return -1;</span><br><span class="line">   &#125;;</span><br><span class="line"></span><br><span class="line">   &#x2F;&#x2F;code from http:&#x2F;&#x2F;caibaojian.com&#x2F;js-splice-element.html</span><br><span class="line">   Array.prototype.remove &#x3D; function(val) &#123;</span><br><span class="line">       var index &#x3D; this.indexOf(val);</span><br><span class="line">       if (index &gt; -1) &#123;</span><br><span class="line">           this.splice(index, 1);</span><br><span class="line">       &#125;</span><br><span class="line">   &#125;;</span><br></pre></td></tr></table></figure>

<p>具体判断逻辑如下：</p>
<ol>
<li>设置一个标志位，第一次为true，表示扩展该节点。扩展之后将该节点的id放到一个全局的扩展节点array里面维护</li>
<li>如果再次点击，该标志位变成false, 执行步骤又可以分为以下几点<ul>
<li>使用vis.js的api获取当前节点的<code>连接</code>节点，<code>network.getConnectedNodes(_thisNode);</code>的<code>_thisNode</code>，为当前操作节点的唯一标识id（此方法还有很多的可选条件参数）</li>
<li>获取<code>连接</code>节点之后，调用<code>nodes.remove(_allChild)</code>，删除关联节点，此操作会直接干掉被删除节点所有的关联关系</li>
<li>删除完成之后，全局表的<code>已扩展</code>节点删除当前点击节点，方便下次再次扩展</li>
</ul>
</li>
</ol>
<h1 id="Q：双向两条箭头合并为一个单向双箭头"><a href="#Q：双向两条箭头合并为一个单向双箭头" class="headerlink" title="Q：双向两条箭头合并为一个单向双箭头"></a>Q：双向两条箭头合并为一个单向双箭头</h1><p>这个需求是比较特殊的例子，涉及到业务的内容不予描述</p>
<p>思路：</p>
<ol>
<li>拿到当前记录，获取当前记录的<code>from</code>和<code>to</code></li>
<li>使用两层循环嵌套，第一层遍历所有的节点一次，第二层遍历当前节点的后面节点，类似冒泡</li>
<li>如果当前节点的<code>from</code> == 其他节点的<code>to</code>，并且当前节点的<code>to</code> == 其他节点的<code>from</code></li>
</ol>
<p>具体代码如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 手动筛选掉双向关联的数据</span><br><span class="line">    function delrepeatinfo(arrName) &#123;</span><br><span class="line">        arrName &#x3D; arrName.edges;</span><br><span class="line">        if (arrName &#x3D;&#x3D; null || arrName.length &#x3D;&#x3D; 0) &#123;</span><br><span class="line">            return null;</span><br><span class="line">        &#125;</span><br><span class="line">        var repeat &#x3D; [];</span><br><span class="line">        for (var i &#x3D; 0; i &lt; arrName.length; i++) &#123;</span><br><span class="line">            var item &#x3D; arrName[i];</span><br><span class="line">            if(item.skip)&#123;</span><br><span class="line">                continue;</span><br><span class="line">            &#125;</span><br><span class="line">            var fromId &#x3D; item.edgeFrom;</span><br><span class="line">            var toId &#x3D; item.edgeTo;</span><br><span class="line">            for (var j &#x3D; i+1; j &lt; arrName.length; j++) &#123;</span><br><span class="line">                var next &#x3D; arrName[j];</span><br><span class="line">                if(next.edgeTo &#x3D;&#x3D; fromId &amp;&amp; next.edgeFrom &#x3D;&#x3D; toId)&#123;</span><br><span class="line">                    repeat.push(item);</span><br><span class="line">                    next.skip &#x3D; true;</span><br><span class="line">                    break;</span><br><span class="line"></span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        return repeat;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h1 id="Q：如果自定义画图"><a href="#Q：如果自定义画图" class="headerlink" title="Q：如果自定义画图"></a>Q：如果自定义画图</h1><p>需求：</p>
<p><img src="https://raw.githubusercontent.com/lazyTimes/imageRepository/master/img/%E6%A0%87%E7%AD%BE%E5%BA%93%E9%9C%80%E6%B1%82.png?ynotemdtimestamp=1595748679079" alt="img"></p>
<p>A：个人无法处理，需要寻找建哥处理按钮的绘画以及按钮的事件触发操作</p>
<p>处理方式：</p>
<ol>
<li>使用canvas在 点击标签之后绘制对应的按钮</li>
<li>监听坐标，当点击了坐标内的按钮触发事件，显示对应的菜单</li>
</ol>
<p>那个多出两个自定义按钮的解决办法如下：</p>
<ol>
<li>利用canvas前端画图技术绘制按钮</li>
<li>监听鼠标的点击坐标，查看是否在绘制的按钮坐标内，对应的触发事件</li>
<li>触发相关操作</li>
</ol>
<p>VIS绘制辅助线条的办法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">context &#x3D; ctx || $(&#39;#network_id&#39;)[0].getContext(&quot;2d&quot;)</span><br><span class="line">context.lineWidth &#x3D; 1;</span><br><span class="line">context.strokeStyle &#x3D; &quot;#CECBCE&quot;;</span><br><span class="line">context.setLineDash([5]);</span><br><span class="line">var offset &#x3D; 800;</span><br><span class="line">var padding &#x3D; 50;</span><br><span class="line">for (var i &#x3D; 0; i &lt; 30; i++) &#123;</span><br><span class="line">    context.beginPath();</span><br><span class="line">    context.moveTo(offset * -1, i * padding - offset)</span><br><span class="line">    context.lineTo(2000, i * padding - offset)</span><br><span class="line">    context.stroke();</span><br><span class="line"></span><br><span class="line">    context.beginPath();</span><br><span class="line">    context.moveTo(i * padding - offset, offset * -1)</span><br><span class="line">    context.lineTo(i * padding - offset, 2000)</span><br><span class="line">    context.stroke();</span><br><span class="line">&#125;</span><br><span class="line">context.setLineDash([]);</span><br></pre></td></tr></table></figure>

<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>neo4j 的资料还是太少太少，多查查官方文档才是硬道理</p>
<p>个人接到的需求如下</p>
<ol>
<li>标签之间都是双向箭头，需要改成一条直线，或者只有单项的。</li>
</ol>
<p>无法自定义，因为数据的展示强制需要 头和尾两个参数，数据本身就是会存在互相关联的情况，所以无法实现</p>
<ol>
<li>标签之间的连接线点击不要有效果，就是颜色不要加深</li>
</ol>
<p>只需要去掉inter``</p>
<ol>
<li>标签展开后能再点击折叠收回映射关系吗？</li>
<li>所有图例鼠标放到上面都变成小手形状</li>
<li>初始化页面这些标签过于分散，需要集中一些，根据屏幕情况集中在一屏展示</li>
</ol>
<p><img src="https://raw.githubusercontent.com/lazyTimes/imageRepository/master/img/%E6%A0%87%E7%AD%BE%E5%BA%93%E9%9C%80%E6%B1%82.png?ynotemdtimestamp=1595748679079" alt="img"></p>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css">
    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>lazytime
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://whitestore.top/2020/07/26/note1/" title="Neo4j + VIS 数据可视化问题汇总">https://whitestore.top/2020/07/26/note1/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLzQuMC96aC1DTg=="><i class="fa fa-fw fa-creative-commons"></i>BY-NC</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E6%95%B0%E6%8D%AE%E5%BA%93/" rel="tag"># 数据库</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/07/26/note25/" rel="prev" title="整理一下个人收集到的一些好网站（持续收集）">
      <i class="fa fa-chevron-left"></i> 整理一下个人收集到的一些好网站（持续收集）
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/07/26/note2/" rel="next" title="《Spring 实战》解读">
      《Spring 实战》解读 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#重要资料："><span class="nav-number">1.1.</span> <span class="nav-text">重要资料：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#VIS-DataSet-使用："><span class="nav-number">1.2.</span> <span class="nav-text">VIS DataSet 使用：</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Q：页面初始化如何控制节点的距离大小"><span class="nav-number">2.</span> <span class="nav-text">Q：页面初始化如何控制节点的距离大小</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Q：要实现鼠标悬停到页面变为小手的样式"><span class="nav-number">3.</span> <span class="nav-text">Q：要实现鼠标悬停到页面变为小手的样式</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Q：如何模仿Neo4j-用vis实现节点的展开和多层折叠"><span class="nav-number">4.</span> <span class="nav-text">Q：如何模仿Neo4j 用vis实现节点的展开和多层折叠</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#个人实现："><span class="nav-number">4.1.</span> <span class="nav-text">个人实现：</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Q：双向两条箭头合并为一个单向双箭头"><span class="nav-number">5.</span> <span class="nav-text">Q：双向两条箭头合并为一个单向双箭头</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Q：如果自定义画图"><span class="nav-number">6.</span> <span class="nav-text">Q：如果自定义画图</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#总结"><span class="nav-number">7.</span> <span class="nav-text">总结</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">阿东</p>
  <div class="site-description" itemprop="description">随遇而安</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">239</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">36</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">37</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;lazyTimes"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOjEwOTc0ODM1MDhAcXEuY29t" title="E-Mail → mailto:1097483508@qq.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly93d3cuNTJwb2ppZS5jbi9ob21lLnBocD9tb2Q9c3BhY2UmdWlkPTE0OTc3MTgmZG89dGhyZWFkJnZpZXc9bWUmZnJvbT1zcGFjZQ==" title="https:&#x2F;&#x2F;www.52pojie.cn&#x2F;home.php?mod&#x3D;space&amp;uid&#x3D;1497718&amp;do&#x3D;thread&amp;view&#x3D;me&amp;from&#x3D;space">吾爱破解</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uaW0vdXNlci8yOTk5MTIzNDUyNjI2MzY2" title="https:&#x2F;&#x2F;juejin.im&#x2F;user&#x2F;2999123452626366">掘金</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL3UvbGF6eXRpbWVz" title="https:&#x2F;&#x2F;segmentfault.com&#x2F;u&#x2F;lazytimes">思否</span>
        </li>
    </ul>
  </div>

      </div>

      <div class="wechat_OA">
        <span>欢迎关注我的公众号</span>
        <br>
          <!-- 这里添加你的二维码图片 -->
        <img src ="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/wechat_channel.jpg">
      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">阿东</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">2m</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">29:50</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'qMUpEEvBgXaMDD1b0ftgi9xr-gzGzoHsz',
      appKey     : 'UCdfT4Rfih6MO6y8DI4fstf6',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
